#!/usr/bin/env node 
// 告诉操作系统，这个文件是node程序，需要使用node来运行
import {program} from 'commander';
import fs from 'fs'
import inquirer from 'inquirer';
import {hasFile,downloadGit} from './utils.js'
const {version} = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
program.version(version) //init-cli -V ===> 1.0.0
// 命令行参数解析
// wl create <name>
// alias : wl c <name>
program.command('create <name>').alias('c').description('创建项目').action(name=>{
    if(hasFile(name)) return console.log('项目已存在')
    inquirer.prompt([
        {
            type:'input',
            name:'projectName',
            message:'项目名称',
            default:name
        },{
            type:'input',
            name:'description',
            message:'项目描述',
            default:'项目描述'
        },{
            type:'list', //confirm
            name:'type',
            message:'选择模式',
            choices:['ts','js']
        }
    ]).then(answers=>{
        const {projectName,type} = answers
        downloadGit(`https://gitee.com/chinafaker/vue-template.git`,projectName)
    })
})
program.parse(process.argv)
